package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author with葡萄成熟时
 * @version 1.0
 */
@RestController("adminOrderController")
@Slf4j
@Api(tags = "管理端订单相关接口")
public class OrderController {
    @Autowired
    private OrderService orderService;


    /**
     * @description: 查询订单详情
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 下午4:13 2024/11/18
     */
    @GetMapping("/admin/order/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> selectOrder(@PathVariable String id) {

        OrderVO orderVO = orderService.selectOrder(id);
        return Result.success(orderVO);
    }

    /**
     * @description: 订单搜索
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 下午4:43 2024/11/18
     */
    @GetMapping("/admin/order/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> selectAndPageOrder(OrdersPageQueryDTO ordersPageQueryDTO) {


        PageResult pageResult = orderService.selectAndPageOrder(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * @description: 各个状态的订单数量统计
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 上午11:33 2024/11/19
     */

    @GetMapping("/admin/order/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result<OrderStatisticsVO> selectOrderStatistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.selectOrderStatistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * @description: 拒单
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 下午12:31 2024/11/19
     */

    @PutMapping("/admin/order/rejection")
    @ApiOperation("拒单")
    public Result rejectOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejectOrder(ordersRejectionDTO);

        return Result.success();
    }

    /**
     * @description: 取消订单
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 下午12:44 2024/11/19
     */

    @PutMapping("/admin/order/cancel")
    @ApiOperation("取消订单")
    public Result cancelOrder(@RequestBody OrdersCancelDTO ordersRejectionDTO) {
        orderService.adminCancelOrder(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * @description: 派送订单
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 下午12:50 2024/11/19
     */

    @PutMapping("/admin/order/delivery/{id}")
    @ApiOperation("派送订单")
    public Result deliveryOrder(@PathVariable Long id) {
        orderService.deliveryOrder(id);
        return Result.success();
    }

    /**
     * @description: 接单
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 下午12:57 2024/11/19
     */

    @PutMapping("/admin/order/confirm")
    @ApiOperation("接单")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.confirmOrder(ordersConfirmDTO);

        return Result.success();
    }
    /**
     * @description: 完成订单
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 下午1:02 2024/11/19
     */

    @PutMapping("/admin/order/complete/{id}")
    @ApiOperation("完成订单")
    public Result completeOrder(@PathVariable Long id){
        orderService.completeOrder(id);
        return Result.success();

    }

}
